package com.example.yuntiku.Servlet;

import com.example.yuntiku.Service.*;
import com.example.yuntiku.dao.impl.ClassDaoImpl;
import com.example.yuntiku.dao.impl.TeacherDao;
import com.example.yuntiku.entity.*;
import com.example.yuntiku.entity.Class;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@WebServlet(name = "TeacherExamServlet", value = "/TeacherExamServlet")
public class TeacherExamServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        ClassDaoImpl classDao=new ClassDaoImpl();
        List<Class> list1=classDao.selectAll();
        PagerService pagerService = new PagerService();
        List<Pager> list = pagerService.selectAll();
        request.setAttribute("list", list);
        request.setAttribute("list1", list1);
        request.getRequestDispatcher("Examchild.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");
        Teacher u = (Teacher) request.getSession().getAttribute("user");
        TeacherDao teacherDao=new TeacherDao();
        Teacher teacher=teacherDao.selectById(u.getTid());
        //作业还是内测
        String type=request.getParameter("type");
        //试卷id
        String rid = request.getParameter("rid");
        //开始考试的时间
        String ks = request.getParameter("ks");
        //考试结束的时间
        String js = request.getParameter("js");
        int teacherid=teacher.getTid();
        //班级id
        String[] sids = request.getParameterValues("sid");
        int userid=2;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExamService examService=new ExamService();
        Exam exam = new Exam();
        exam.setPagerid(Integer.parseInt(rid));
        exam.setClassid(Integer.parseInt(type));
        exam.setHub("株洲科泰");
        exam.setStarttime(ks);
        exam.setTerminaltime(js);
        exam.setTeacherid(teacherid);
        exam.setTesttime(format.format(new Date()));
        exam.setEtype(1);
        int ii= examService.insertExam1(exam,sids);
        response.sendRedirect("ExamServlet");
        /*
        * 这个项目不仅提高了我们对Java Web开发流程的理解，也锻炼了我们的团队协作能力，特别是在解决问题和代码优化方面积累了宝贵的经验。*/
    }
}